package com.distortiongames.escalol.components.render.settings
{
	import com.distortiongames.elysium.math.Vector2D;
	import com.distortiongames.escalol.components.render.CircleRenderer;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class TrailRenderer extends CircleRenderer
	{
		private var tail:Array;
		
		override protected function onAdd():void
		{
			super.onAdd();
			tail = new Array();
			for (var i:int = 0; i < radius * 2; i++)
			{
				tail[i] = position.copy();
			}
		}
		
		override public function onFrame():void
		{
			for (var i:int = 1; i < tail.length; i++)
			{
				tail[i - 1].x = tail[i].x;
				tail[i - 1].y = tail[i].y;
			}
			tail[tail.length - 1] = position;
			super.onFrame();
		}
		
		override public function doRender():void
		{
			sprite.graphics.clear();
			for (var i:int = 0; i < tail.length; i++)
			{
				var tempPosition:Vector2D = tail[i];
				sprite.graphics.beginFill(fill.color, (i == tail.length - 1) ? 1 : .3);
				sprite.graphics.drawCircle(tempPosition.x, tempPosition.y, i / 2);
				sprite.graphics.endFill();
			}
		}
	}

}